<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员控制面板</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/admin.css') }}">
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js"></script>
</head>
<body>
    <!-- 导航栏 -->
    <nav>
        <ul>
            <li><a href="{{ url_for('admin_dashboard') }}">主页</a></li>
            <li><a href="{{ url_for('admin_profile') }}">个人信息</a></li>
            <li><a href="{{ url_for('admin_logout') }}" class="logout-btn">登出</a></li>
            <li><a href="{{ url_for('admin_login') }}" class="switch-account-btn">切换账号</a></li>
        </ul>
    </nav>

    <!-- 当前时间显示 -->
    <div class="current-time">
        <p id="current-time"></p>
    </div>

    <!-- 管理员信息 -->
    <div class="admin-info">
        <p>职位: {{ admin_info[2] }}</p>
        <p>姓名: {{ admin_info[0] }}</p>
        <p>电子邮箱: {{ admin_info[1] }}</p>
    </div>

    <!-- 添加新产品 -->
    <div class="section">
        <h2 class="section-title">添加新产品 <span class="toggle-icon">▼</span></h2>
        <div class="section-content">
            <form action="{{ url_for('add_product') }}" method="post" enctype="multipart/form-data">
                <input type="text" name="name" placeholder="产品名称" required>
                <textarea name="description" placeholder="产品描述" required></textarea>
                <input type="text" name="price" placeholder="价格" required>
                <input type="number" name="stock" placeholder="库存数量" required>
                <input type="file" name="image" required>
                <select name="category" required>
                    <option value="" disabled selected>选择分类</option>
                    <option value="Electronics">电子产品</option>
                    <option value="Books">书籍</option>
                    <option value="Clothing">服装</option>
                    <option value="Furniture">家具</option>
                    <option value="Toys">玩具</option>
                    <option value="Groceries">杂货</option>
                    <option value="Sports">体育用品</option>
                    <option value="Health">健康与美容</option>
                    <option value="Jewelry">珠宝</option>
                    <option value="Gardening">园艺</option>
                    <option value="Pet Supplies">宠物用品</option>
                    <option value="Footwear">鞋类</option>
                    <option value="Automotive">汽车用品</option>
                </select>
                <button type="submit">添加产品</button>
            </form>
        </div>
    </div>

    <!-- 产品列表 -->
    <div class="section">
        <h2 class="section-title">产品列表 <span class="toggle-icon">▼</span></h2>
        <div class="section-content">
            <form method="get" action="{{ url_for('admin_dashboard') }}">
                <input type="text" name="search" placeholder="搜索产品" value="{{ search_query }}">
                <button type="submit">搜索</button>
            </form>
            <table>
                <tr>
                    <th>名称</th>
                    <th>描述</th>
                    <th>价格</th>
                    <th>分类</th>
                    <th>库存</th>
                    <th>操作</th>
                </tr>
                {% for product in products %}
                <tr>
                    <td>{{ product.name }}</td>
                    <td>{{ product.description }}</td>
                    <td>{{ product.price }}</td>
                    <td>{{ product.category }}</td>
                    <td>{{ product.stock }}</td>
                    <td>
                        <a href="{{ url_for('edit_product', id=product.id) }}">编辑</a>
                        <a href="{{ url_for('delete_product', id=product.id) }}">删除</a>
                    </td>
                </tr>
                {% endfor %}
            </table>
            <div class="pagination">
                {% if page > 1 %}
                    <a href="{{ url_for('admin_dashboard', page=page-1, search=search_query) }}">上一页</a>
                {% endif %}
                {% for p in range(1, total_pages + 1) %}
                    {% if p == page %}
                        <span>{{ p }}</span>
                    {% else %}
                        <a href="{{ url_for('admin_dashboard', page=p, search=search_query) }}">{{ p }}</a>
                    {% endif %}
                {% endfor %}
                {% if page < total_pages %}
                    <a href="{{ url_for('admin_dashboard', page=page+1, search=search_query) }}">下一页</a>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 其他部分内容 -->
    <div class="section">
        <h2 class="section-title">用户联系信息 <span class="toggle-icon">▼</span></h2>
        <div class="section-content">
            <a href="{{ url_for('admin_contacts') }}">查看所有联系信息</a>
        </div>
    </div>
    <div class="section">
        <h2 class="section-title">交易记录 <span class="toggle-icon">▼</span></h2>
        <div class="section-content">
            <a href="{{ url_for('admin_orders') }}">查看所有交易记录</a>
        </div>
    </div>
    <div class="section">
        <h2 class="section-title">每日销量 <span class="toggle-icon">▼</span></h2>
        <div class="section-content">
             <li><a href="{{ url_for('admin_sales') }}">每日销量</a></li>
        </div>
    </div>

    <script src="{{ url_for('static', filename='js/admin.js') }}"></script>
</body>
</html>
